package com.example.pointsaddition;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

	TextView Streak = null;
	TextView UserPoints = null;
	TextView QuestionPoints = null;
	Button Add = null;
	Button Subtract = null;

	int streak = 0;
	int u_points = 0;
	static int q_points = 1;
	int j;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		Streak = (TextView) findViewById(R.id.streakTextView);
		UserPoints = (TextView) findViewById(R.id.userPointTextView1);
		QuestionPoints = (TextView) findViewById(R.id.qPointTextView1);
		Add = (Button) findViewById(R.id.addButton);
		Subtract = (Button) findViewById(R.id.subtractButton);

		fun(0);

	}

	void fun(int i) {

		if (i < 24) {
			j = i;
			q_points=getQuestionPoints();
			Streak.setText("" + streak);
			UserPoints.setText("" + u_points);
			QuestionPoints.setText("" + q_points);

			Add.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {

					streak++;
					u_points += q_points;

					fun(++j);
				}
			});

			Subtract.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {

					--streak;
					u_points -= q_points;

					fun(++j);
				}
			});
			setQuestionPoints(streak);

		} else {
			finish();
		}

	}

	@Override
	public void finish() {
		// TODO Auto-generated method stub
		super.finish();
	}
	
	void setQuestionPoints(int streak){
		int que_points=1;
		if(streak!=0){
			que_points=(streak/7)+1;
		}else{
			que_points=1;
		}
		this.q_points=que_points;
	}
	
	int getQuestionPoints(){
		return this.q_points;
	}

}
